package com.nengchuan.eic.nceconomy.filter;

import org.slf4j.MDC;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
import java.util.UUID;

/**
 * 功能描述:
 *
 * @Author: liurui
 * @Date: 2020/4/15 0015 下午 4:03
 */
@WebFilter(filterName = "logbackFilter", urlPatterns = "/*")
public class LogbackFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        UUID uuid = UUID.randomUUID();
        MDC.put("traceid", uuid.toString().replace("-",""));
        try {
            filterChain.doFilter(servletRequest,servletResponse);
        }finally {
            MDC.remove("traceid");
        }
    }
    @Override
    public void destroy() {
    }
}
